/*****************************************************************************
 *
 * Copyright (c), 2004-2020,ShangHai Neotune Information Technology Co., Ltd.
 *
 * Module Name : v3_eng.h
 *
 * Author :    sean
 *
 * Date :    2004-02-05
 *
 * Version :    1.00
 *
 * Description :    
 *
 * Other :    
 *
 * Data Structure List: <Main Data Structure>
 *
 * Modification History
 * ---------------------------------------------------------------------------
 *  1: Data :      2004-02-05
 *    Author :     sean
 *    Version :    V100R001M00
 *    Modification : creation
 *
*****************************************************************************/

#if (!defined(v3_eng_inc))
#define v3_eng_inc

#ifdef __cplusplus
extern"C" {
#endif

#include "asn1.h"

#include "buffer_snmp.h"
#include "snmpdefs.h"

#define ETC_ENGINE_ENGINE_MAX 32

#ifdef NEOSNET_STRUCT_ALIGN
#pragma align 1
#endif

typedef struct ENGINE_LEAF_S 
        {
        struct ENGINE_LEAF_S *next;
        bits8_t  *id;
        ALENGTH_T id_len;
        bits32_t  boots;
        sbits32_t offset;
        sbits32_t lasttime;
#if INSTALL_ENVOY_SNMP_V3_TARGET
        OBJ_ID_T        tdomain;        /* information to allow us to find */ 
        EBUFFER_T       taddress;       /* a remote engineid for informs   */
#endif
        } ENGINE_LEAF_T;

#ifdef NEOSNET_STRUCT_ALIGN
#pragma align 0
#endif

#ifndef ENVOY_ADD_ENGINE_ADDRESS
#if (INSTALL_ENVOY_SNMP_V3_TARGET)
extern int   envoy_add_engine_address __((SNMP_PKT_T *, SNMPADDR_T *, int));

#define ENVOY_ADD_ENGINE_ADDRESS(P, A, C) \
    envoy_add_engine_address((P), (A), (C))
#elif defined(ENVOY_ADD_ENGINE_ID)
#define ENVOY_ADD_ENGINE_ADDRESS(P, A, C) (ENVOY_ADD_ENGINE_ID(P), 1)
#endif
#endif

/* global variables */
extern sbits32_t      v3_snmpEngineMaxMessageSize;
extern ENGINE_LEAF_T *v3_my_engine;
extern ENGINE_LEAF_T *root_engine;

extern int SNMP_Engine_Set_My_Info __((bits8_t *, ALENGTH_T,
                                       bits32_t, sbits32_t));
#define SNMP_Engine_Get_My_ID()        (v3_my_engine ? v3_my_engine->id : 0)
#define SNMP_Engine_Get_My_ID_Length() (v3_my_engine ? v3_my_engine->id_len : 0)
#define SNMP_Engine_Get_My_Boots()     (v3_my_engine ? v3_my_engine->boots : 0)
#define SNMP_Engine_Get_My_Time()      (v3_my_engine ? \
                                     (ENVOY_TIME()) - v3_my_engine->offset : 0)

#define SNMP_Engine_Get_Boots(E)     ((E)->boots)
#define SNMP_Engine_Get_Time(E)      ((ENVOY_TIME()) - (E)->offset)
#define SNMP_Engine_Get_LastTime(E)  ((E)->lasttime)

#define SNMP_Engine_Set_Info(E, B, T) ((E)->boots = (B), \
                                       (E)->offset = (ENVOY_TIME()) - (T),\
                                       (E)->lasttime = (T))

extern void SNMP_Find_Matching_Engine_ID __((OBJ_ID_T *, EBUFFER_T *,
                                             bits8_t **, ALENGTH_T *));
extern int             SNMP_Engine_Set_Address __((bits8_t *, ALENGTH_T,
                                                   OIDC_T *, int,
                                                   bits8_t *, ALENGTH_T));
extern ENGINE_LEAF_T * SNMP_Engine_Lookup  __((bits8_t *, ALENGTH_T));
extern int             SNMP_Engine_Install __((bits8_t *, ALENGTH_T,
                                              bits32_t, sbits32_t));

extern void            get_snmpEngineID __((OIDC_T, int, OIDC_T *, 
                                            SNMP_PKT_T *, VB_T *));
extern void            get_snmpEngineBoots __((OIDC_T, int, OIDC_T *,
                                               SNMP_PKT_T *, VB_T *));
extern void            get_snmpEngineTime __((OIDC_T, int, OIDC_T *,
                                              SNMP_PKT_T *, VB_T *));

#ifdef __cplusplus
}
#endif

#endif /* (!defined(v3_eng_inc)) */


